#pragma once

#pragma pack(push)
#pragma pack(1)

#define PACKET_TYPE_DIFF                            0x00000001L
#define PACKET_TYPE_CREATE_EMAIL                    0x00000002L
#define PACKET_TYPE_CREATE_FEED                     0x00000003L

#define PACKET_SUBTYPE_REQUEST                      0x00000001L
#define PACKET_SUBTYPE_ANSWER                       0x00000002L

#define OPERATION_STATUS_SUCCESSFUL                 0x00000000L
#define OPERATION_STATUS_NOT_FOUND                  0x00000001L
#define OPERATION_STATUS_DB_ERROR                   0x00000002L
#define OPERATION_STATUS_EMAIL_CREATION_ERROR       0x00000003L
#define OPERATION_STATUS_FEED_CREATION_ERROR        0x00000004L

#define DHL_TYPE_ALL_PAGE                           0x00000001L
#define DHL_TYPE_ONLY_CHANGES_SUMMARY               0x00000002L

#define FEED_TYPE_RSS                               0x00000001L
#define FEED_TYPE_ATOM                              0x00000002L

typedef struct _PACKET_DATA_REQUEST_DIFF
{
    unsigned int   monitor_id;
    unsigned int   resource1_id;
    unsigned int   resource2_id;
    int            highlight_font_color;
    int            highlight_bk_color;
    unsigned int   highlight_font_style;
    unsigned int   dhl_type;
}
PACKET_DATA_REQUEST_DIFF, *PPACKET_DATA_REQUEST_DIFF;

typedef struct _PACKET_DATA_ANSWER_DIFF
{
    unsigned int   operation_status;
    unsigned int   triggers_count;
    unsigned int   diff_result_length;
    char           diff_result[1];
}
PACKET_DATA_ANSWER_DIFF, *PPACKET_DATA_ANSWER_DIFF;

typedef struct _PACKET_DATA_REQUEST_CREATE_EMAIL
{
    unsigned int    total_size;
    unsigned int    account_id;
    unsigned int    monitor_id;
    unsigned char   email_content_type;
    int             alert_at_time;
    unsigned int    email_from_length;
    char            email_from[1];
    unsigned int    email_to_length;
    char            email_to[1];
    unsigned int    email_cc_length;
    char            email_cc[1];
    unsigned int    email_bcc_length;
    char            email_bcc[1];
    unsigned int    variables_length;
    char            variables[1];    
    unsigned int    email_template_name_length;
    char            email_template_name[1];
    unsigned int    email_subject_length;
    char            email_subject[1];
    unsigned int    email_template_length;
    char            email_template[1];
}
PACKET_DATA_REQUEST_CREATE_EMAIL, *PPACKET_DATA_REQUEST_CREATE_EMAIL;

typedef struct _PACKET_DATA_ANSWER_CREATE_EMAIL
{
    unsigned int   operation_status;
}
PACKET_DATA_ANSWER_CREATE_EMAIL, *PPACKET_DATA_ANSWER_CREATE_EMAIL;

typedef struct _PACKET_DATA_REQUEST_CREATE_FEED
{
    unsigned int   monitor_id;
    unsigned int   feed_type;
}
PACKET_DATA_REQUEST_CREATE_FEED, *PPACKET_DATA_REQUEST_CREATE_FEED;

typedef struct _PACKET_DATA_ANSWER_CREATE_FEED
{
    unsigned int   operation_status;
}
PACKET_DATA_ANSWER_CREATE_FEED, *PPACKET_DATA_ANSWER_CREATE_FEED;

typedef union _PACKET_DATA
{
    PACKET_DATA_REQUEST_DIFF            packetDataRequestDiff;
    PACKET_DATA_ANSWER_DIFF             packetDataAnswerDiff;
    PACKET_DATA_REQUEST_CREATE_EMAIL    packetDataRequestCreateEmail;
    PACKET_DATA_ANSWER_CREATE_EMAIL     packetDataAnswerCreateEmail;
    PACKET_DATA_REQUEST_CREATE_FEED     packetDataRequestCreateFeed;
    PACKET_DATA_ANSWER_CREATE_FEED      packetDataAnswerCreateFeed;
}
PACKET_DATA;

typedef struct _PACKET_HEADER
{
    unsigned int       type;
    unsigned int       subtype;
}
PACKET_HEADER, *PPACKET_HEADER;

typedef struct _PACKET
{
    PACKET_HEADER        header;
    PACKET_DATA          data;
}
PACKET, *PPACKET;

#pragma pack(pop)